const Router = require('koa-router')
const router = new Router()
const cors = require('koa-cors')
const Mock = require('mockjs')

//people
const mockPeople = Mock.mock({
    'peoples|10': [{
        'id|+1': 1,
        'guid': '@guid',
        'name': '@cname',
        'age': '@integer(20, 50)',
        'birthday': '@date("MM-dd")',
        'address': '@county(true)',
        'email': '@email',
    }]
});

//ctx.params 路由传值
//ctx.query  参数传值
//ctx.request.body Post参数

router.get('/userInfo', async (ctx, next) => {
    console.log(ctx.query);
    // 允许cors跨域请求
    await cors();
    ctx.body = JSON.stringify(mockPeople['peoples'], null, 2);
})

// 导出 router 实例
module.exports = router